;(function(){
		jQuery.fn.banner1=function(wide){
			var _this=this;
			$banner = $(".focus")
			$abttn=$(this).find(".btn").children()
			$aImg=$(this).find(".bigImg").children()
			// console.log($aImg)
			function  Carousel(abttn,aImg,_this){
				this.wide=wide;
				this._this=	_this;		
				this.abttn=abttn;
				this.aImg=aImg;
				this.pictureNum=0;
				this.iNow=0;//当前图片下标，设定最开始，第一张是0
				this.iNext=1;//当前图片的下一张，设定最开始为1
				this.iBor=this.aImg.length-1;
				 this.init();
				 console.log(this.aImg,$aImg)
			}
			
			Carousel.prototype.init=function(){
				var that=this;
				// console.log($aImg.length,this.iNow,this.iBor)
				this.abttn.on("mouseenter",function(){
					// console.log($(this).index())
					that.pictureNum = $(this).index()
					   that.show();
					   that.change();
				})
			 this.timing();
		 	}
					
			Carousel.prototype.show=function(){
				if(this.pictureNum==this.iNow){
					return 0					
				}
				if(this.pictureNum > this.iNow){
					this.aImg.eq(this.iNow)
					.stop()
					.animate({
						left:this.wide
					})
					this.iNow=this.pictureNum//给iNow赋值
					this.aImg.eq(this.iNow)
					.css({
						left:-this.wide//设置初始值
					})
					.stop()
					.animate({
						left:0
					})
					 this.change();
				}else{
					this.aImg.eq(this.iNow)//把之前的iNow图移到左边
					.stop()
					.animate({
						left:-this.wide
					})
					this.iNow=this.pictureNum
					this.aImg.eq(this.iNow)
					.css({
						left:this.wide//设置初始值
					})
					.stop()
					.animate({
						left:0
					})
				}
				 this.change();
			}

			Carousel.prototype.changeIndex=function(){
				if(this.iNow==this.aImg.length-1){
					this.iNow=0
					this.iBor=this.aImg.length-1

				}else{
					this.iNow++
					this.iBor=this.iNow-1

				}
				this.aImg.eq(this.iNow)
				.css({
					left:-wide//设置初始值
				})
				.stop()
				.animate({
					left:0
				})

				this.aImg.eq(this.iBor)
				.css({
					left:0//设置初始值
				})
				.stop()
				.animate({
					left:this.wide
				})
				// console.log(this.pictureNum)
			}
			Carousel.prototype.change = function(){
				
				 this.abttn.eq(this.iNow)				 	
					.css({
						opacity: 1,
						height:"50px",
						"line-height":"50px",
						marginTop:0				
					})	
					.siblings("span")					
					.css({
						opacity: 0.4,
						height:"40px",
						"line-height":"40px",
						marginTop:"10px"				

					})
				if($(".btn").find("p").hasClass('active')){
					$(".btn").find("p").removeClass('active')
				}
				$(".btn").find("p").eq(this.iNow).addClass('active')

			}

			Carousel.prototype.timing=function(){
				var timer = null;
				var that = this;
				timer = setInterval(function(){
					that.changeIndex()
					that.change()
				},2000);
				$banner.on("mouseenter",function(){
					clearInterval(timer);
				})
				$banner.on("mouseleave",function(){
					timer = setInterval(function(){
						that.changeIndex()
						that.change()
					},2000);
				})	 
			}
			new Carousel($abttn,$aImg,_this,wide)	
		 }
	})()

